package com.pxmeta.app.controller.game;


import cn.dev33.satoken.annotation.SaCheckLogin;
import com.google.common.collect.Maps;
import com.pxmeta.common.core.domain.AjaxResult;
import com.pxmeta.common.utils.SecurityUtils;
import com.pxmeta.party.entity.dto.InputSeasoningDTO;
import com.pxmeta.party.entity.vo.ActivityFoodRecordVO;
import com.pxmeta.party.entity.vo.ActivityFoodSuccessVO;
import com.pxmeta.party.entity.vo.ActivityFoodVO;
import com.pxmeta.party.service.IActivityFoodStallService;
import com.pxmeta.user.entity.User;
import com.pxmeta.user.service.IUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;

@RestController
@RequestMapping("/activity")
@Api(value = "派对活动-美食大排档",tags = "派对活动-美食大排档")
@RequiredArgsConstructor
public class ActivityController {
    private final IActivityFoodStallService activityFoodStallService;

    private final IUserService userService;

    @SaCheckLogin
    @GetMapping("/getFoodStall")
    @ApiOperation("获取吃货大排档")
    public AjaxResult getFoodActivity(){
        Long userId = SecurityUtils.getUserId();
        List<ActivityFoodVO> list = activityFoodStallService.getFoodStallList(userId);
        return AjaxResult.success(list);
    }


    @PostMapping("/addFoodStallBalance")
    @ApiOperation("添加吃货大排档余额")
    @SaCheckLogin
    public AjaxResult addFoodStallBalance(@RequestParam Integer count){
        Long userId = SecurityUtils.getUserId();
        User user = userService.getById(userId);
        BigDecimal balance = user.getBalance();
        if (balance.intValue()<count){
            return AjaxResult.error("余额不足！");
        }
        user.setBalance(balance.subtract(BigDecimal.valueOf(count)));
        Integer foodStallBalance = user.getFoodStallBalance();
        foodStallBalance+=count;
        user.setFoodStallBalance(foodStallBalance);
        userService.updateById(user);

        return AjaxResult.success();
    }

    @SaCheckLogin
    @PostMapping("/inputSeasoning")
    @ApiOperation("放入调料")
    public AjaxResult inputSeasoning(@RequestBody InputSeasoningDTO vo){
        Long userId = SecurityUtils.getUserId();
        Integer status = activityFoodStallService.inputSeasoning(userId, vo.getCount(), vo.getId());
        HashMap<String, Object> map = Maps.newHashMap();
        map.put("status", status);
        return AjaxResult.success(map);
    }

    @GetMapping("/getFoodStallSuccessList")
    @ApiOperation("获取吃货大排档成功记录")
    public AjaxResult getFoodStallSuccessList(@RequestParam Integer page,
                                              @RequestParam Integer size,
                                              @RequestParam(required = false) Integer number){
        List<ActivityFoodSuccessVO> list = activityFoodStallService.getSuccessList(page, size, number);
        return AjaxResult.success(list);
    }

    @GetMapping("/getMyFoodStallRecords")
    @ApiOperation("获取我的记录")
    public AjaxResult getMyFoodStallRecords(@RequestParam Integer page,
                                            @RequestParam Integer size,
                                            @RequestParam Integer status){
        Long userId = SecurityUtils.getUserId();
        List<ActivityFoodRecordVO> list = activityFoodStallService.getMyFoodStallRecords(page,size,userId, status);
        return AjaxResult.success(list);
    }

//
//    @GetMapping("/getFoodStallItemList")
//    @ApiOperation("获取所有批次")
//    public AjaxResult getFoodStallItemList(){
//        activityFoodStallService
//
//
//        return AjaxResult.success();
//    }




}
